import React from 'react';
import {
  Tooltip,
  Popover,
  message,
  Badge,
  Divider,
  Icon,
  Popconfirm,
  Progress,
  Rate,
  Select,
  Tag,
} from 'antd';
import moment from 'moment';

const Option = Select.Option;

export default {
  showMessage: (type, time, callback) => {
    message[type](`恭喜你,这个是${type}`, time).then(res => {
      if (callback) {
        callback();
      }
    });
  },

  // 操作
  operation(_this) {
    return (text, record, index) => {
      return (
        <div>
          <a onClick={() => _this.openOrderMapPage(record.id)}>
            <Icon type="edit" style={{ marginRight: 2 }} />
            订单详情
          </a>
          <Divider type="vertical" />
          <Popconfirm
            placement="rightBottom"
            title="数据删除将不可以恢复,确定删除?"
            onConfirm={_this.handleLineDelete}
            cancelText="否"
            okText="是"
          >
            <a href="">
              <Icon type="delete" style={{ marginRight: 2 }} />
              删除
            </a>
          </Popconfirm>
          <Divider type="vertical" />
          <a onClick={_this.handleLineDelete}>
            {' '}
            <Icon type="delete" style={{ marginRight: 2 }} />
            结束订单
          </a>
          {/* <Divider type="vertical"/> */}
          {/*<a onClick={() => this.handleOperator('detail')}>员工详情</a>*/}
        </div>
      );
    };
  },

  getOptionList(data) {
    if (!data) {
      return [];
    }
    let options = []; //[<Option value="0" key="all_key">全部</Option>];
    data.map(item => {
      options.push(
        <Option value={item.value} key={item.value}>
          {item.name}
        </Option>,
      );
    });
    return options;
  },

  tooltip: oData => (
    <span>
      {oData['title']}&nbsp;
      <Tooltip title={oData['help']}>
        <Icon type="question-circle-o" />
      </Tooltip>
    </span>
  ),

  //徽章
  badge: (data, text) => (params, record) => {
    if (data[params]) {
      return (
        <>
          {' '}
          <Badge {...data[params]} />
          {record[text] ? record[text] : null}
        </>
      );
    } else {
      return (
        <>
          {' '}
          <Badge status="default" text="未知" />
        </>
      );
    }
  },

  ropover: data => (text, record, index) => (
    <Popover arrowPointAtCenter placement="top" title={text} content={record[data]} trigger="click">
      <a>{text}</a>
    </Popover>
  ),

  //时间格式化
  moment: timeFormat => params => {
    console.log(timeFormat);
    if (!timeFormat) {
      var timeFormat = 'YYYY-MM-DD hh:mm:ss';
    }
    return <span>{moment(params).format(timeFormat)}</span>;
  },

  //评分
  rate: () => params => <Rate allowHalf defaultValue={Math.round(params / 12)} />,

  //圆形进度
  progressCircle: () => params => <Progress type="circle" percent={params} width={40} />,

  //标签
  tag: data => params => {
    if (data) {
      return (
        <span>
          {' '}
          <Tag key={params} {...data[params]}>
            {data[params].text}
          </Tag>
        </span>
      );
    }
  },
};
